﻿using System.IO;

namespace TroubleshootingofBeanBagAssistant.lCheck
{
	public class ErrorLogsCheck : IDiagnosticCheck
	{
		public string Name => "错误日志检测";

		public CheckResult Run()
		{
			// 推荐用当前用户路径
			string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
			string logDir = Path.Combine(appDataPath, @"Programs\BeanBagAIBrowserEdge\Applications\BeanBagAI\LogsError");

			try
			{
				if (Directory.Exists(logDir))
				{
					var files = Directory.GetFiles(logDir, "*.*", SearchOption.TopDirectoryOnly);
					if (files.Length > 0)
					{
						return new CheckResult
						{
							Title = "检测到应用运行异常，存在错误日志",
							Detail = $"日志文件数: {files.Length}"
						};
					}
					else
					{
						return new CheckResult
						{
							Title = "未检测到错误日志",
							Detail = "应用运行正常"
						};
					}
				}
				else
				{
					return new CheckResult
					{
						Title = "未检测到错误日志目录",
						Detail = "应用运行正常"
					};
				}
			}
			catch (Exception ex)
			{
				return new CheckResult
				{
					Title = "检查错误日志时发生异常",
					Detail = ex.Message
				};
			}
		}
	}
}
